import { Button } from 'antd';
import { ReactNode } from 'react';

export type CommandFormFooterProps = {
  showCancel?: boolean;
  showPreview?: boolean;
  showSubmit?: boolean;
  onClose?: VoidFunction;
  onPreview?: VoidFunction;
  onSubmit?: VoidFunction;
  cancelText?: string;
  previewText?: string;
  submitText?: string;
  isPreviewLoading?: boolean;
  isSubmitLoading?: boolean;
  isPreviewDisabled?: boolean;
  isSubmitDisabled?: boolean;
  children?: ReactNode;
};

export const CommandFormFooter = ({
  showCancel = true,
  showPreview = false,
  showSubmit = true,
  onClose,
  onPreview,
  onSubmit,
  cancelText = '取消',
  previewText = '预览',
  submitText = '确认',
  isPreviewLoading,
  isSubmitLoading,
  isPreviewDisabled,
  isSubmitDisabled,
  children,
}: CommandFormFooterProps) => {
  return (
    <div className='form-dialog_footer'>
      {children}
      <div className='form-dialog_footer-buttons'>
        {showCancel && <Button onClick={onClose}>{cancelText}</Button>}
        {showPreview && (
          <Button
            onClick={onPreview}
            disabled={isPreviewDisabled}
            loading={isPreviewLoading}
          >
            {previewText}
          </Button>
        )}
        {showSubmit && (
          <Button
            type='primary'
            htmlType='submit'
            onClick={onSubmit}
            disabled={isSubmitDisabled}
            loading={isSubmitLoading}
          >
            {submitText}
          </Button>
        )}
      </div>
    </div>
  );
};
